﻿using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Media;
using System.Windows.Shapes;
using NUnit.Framework;
using Chambills.PopUpBehavior;

namespace Chambills.PopUpBehaviour.Tests
{
    public partial class DisableBackgroundBehaviourTestCase
    {

         [TestFixture, RequiresSTA]
        public class DisableBackgroundBehaviourWhenEnabledScenario
        {
            private Grid host;
            private DisableBackGroundBehaviour behaviour;
            private Rectangle rectangle;

            [SetUp]
            public void SetUp()
            {
                behaviour = new DisableBackGroundBehaviour();
                host = new Grid();
                host.ColumnDefinitions.Add(new ColumnDefinition());
                host.ColumnDefinitions.Add(new ColumnDefinition());
                host.ColumnDefinitions.Add(new ColumnDefinition());
                host.RowDefinitions.Add(new RowDefinition());
                host.RowDefinitions.Add(new RowDefinition());
                Interaction.GetBehaviors(host).Add(behaviour);
                rectangle = host.VisualChildren().First() as Rectangle;
            }

            [Test]
            public void RectangleIsAddedToHost()
            {
                Assert.IsNotNull(rectangle);
            }

            [Test]
            public void EnabledCanBeSetBeforeAttaching()
            {
                behaviour = new DisableBackGroundBehaviour { Enabled = true };
            }

             [Test]
             public void BackgroundIsBindable()
             {
                 var box = new TextBox();
                 BindingOperations.SetBinding(behaviour, DisableBackGroundBehaviour.BackgroundProperty, new Binding("Background") { Source = box, Mode = BindingMode.TwoWay });
                 box.Background = Brushes.Turquoise;
                 Assert.AreEqual(Brushes.Turquoise, behaviour.Background);
             }
             

             [Test]
             public void OpacityIsBindable()
             {
                 var box = new TextBox();
                 BindingOperations.SetBinding(behaviour, DisableBackGroundBehaviour.OpacityProperty , new Binding("Opacity") { Source = box, Mode = BindingMode.TwoWay });
                 box.Opacity = 0.88;
                 Assert.AreEqual(0.88, behaviour.Opacity);
             }

             [Test]
             public void AddedGridShouldSpanAllHostRows()
             {
                 Assert.AreEqual(Grid.GetRowSpan(rectangle), host.RowDefinitions.Count);
             }

             [Test]
             public void CursorIsBusy()
             {
                 Assert.AreEqual(rectangle.Cursor, Cursors.Wait);
             }

             [Test]
             public void AddedGridShouldSpanAllHostColumns()
             {
                 Assert.AreEqual(Grid.GetColumnSpan(rectangle), host.ColumnDefinitions.Count);
             }
        }

    }
}
